<?php
	include_once 'isLogin.php';
	$infoc=new info(); 		//咨询列
	$userc=new user();		//用户类
	$groupc=new group();	//管理员

	$state= array('stay' =>'等待','pass' =>'通过', 'refuse' =>'拒绝');

	//删除
	$table_name="info";
	if($_GET['action']=='del'){
		$ids=$_POST['id'];
		echo $res=$infoc->info_del($ids);
		exit();
	}

	
	//读取所有用户
	$user_list=$userc->userList();
	$user_list=$user_list['result'];
	//读取所有管理员
	$admin=$groupc->admin_group_list();
	$admin=$admin['result'];

	if($_GET){
		$where=" AND i.title like '%".$_GET['title']."%'";
		$smarty->assign('search',$_GET);
	}



	$row=$infoc->info_list($where);
	$page=$row['page'];
	$row=$row['result'];
	for ($i=0; $i <count($row) ; $i++) { 
		if($row[$i]['type']=='admin'){
			for ($j=0; $j <count($admin) ; $j++) { 
				if($row[$i]['group_id']==$admin[$j]['id']){
					$row[$i]['user_name']=$admin[$j]['group_name'];

				}
			}
		}elseif($row[$i]['type']=='user'){
			for ($j=0; $j <count($user_list) ; $j++) { 
				if($row[$i]['user_id']==$user_list[$j]['id']){
					$row[$i]['user_name']=$user_list[$j]['account'];
				}
			}
		}
		$row[$i]['create_time']=date('Y-m-d H:i:s',$row[$i]['create_time']);
		$row[$i]['state_name']=$state[$row[$i]['check']];
	}


	$smarty->assign("row",$row);
	$smarty->assign('page',$page);
	
	$smarty->display("info_list.html");
?>